<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The Event class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="event.constructing.signal.events.html">Constructing signal events</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="event.add.html">Event::add</a></div>
 <div class="up"><a href="book.event.html">Event</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.event" class="reference">
 <h1 class="title">The Event class</h1>
 
 <div class="partintro"><p class="verinfo">(PECL event &gt;= 1.2.6-beta)</p>

  <div class="section" id="event.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    <strong class="classname">Event</strong>
    class represents and event firing on a file descriptor being ready to read
    from or write to; a file descriptor becoming ready to read from or write
    to(edge-triggered I/O only); a timeout expiring; a signal occuring; a
    user-triggered event.
   </p>
   <p class="para">
    Every event is associated with
    <a href="class.eventbase.html" class="classname">EventBase</a>
    . However, event will never fire until it is
    <em class="emphasis">added</em>
    (via
    <span class="methodname"><a href="event.add.html" class="methodname">Event::add()</a></span>
    ). An added event remains in
    <em class="emphasis">pending</em>
    state until the registered event occurs, thus turning it to
    <em class="emphasis">active</em>
    state. To handle events user may register a callback which is called when
    event becomes active. If event is configured
    <em class="emphasis">persistent</em>
    , it remains pending. If it is not persistent, it stops being pending when
    it&#039;s callback runs.
    <span class="methodname"><a href="event.del.html" class="methodname">Event::del()</a></span>
    method
    <em class="emphasis">deletes</em>
    event, thus making it non-pending. By means of
    <span class="methodname"><a href="event.add.html" class="methodname">Event::add()</a></span>
    method it could be added again.
   </p>
  </div>

  <div class="section" id="event.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">final</span>
      <strong class="classname">Event</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.event.html#event.constants.et"><var class="varname">ET</var></a></var>
     <span class="initializer"> = 32</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.event.html#event.constants.persist"><var class="varname">PERSIST</var></a></var>
     <span class="initializer"> = 16</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.event.html#event.constants.read"><var class="varname">READ</var></a></var>
     <span class="initializer"> = 2</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.event.html#event.constants.write"><var class="varname">WRITE</var></a></var>
     <span class="initializer"> = 4</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.event.html#event.constants.signal"><var class="varname">SIGNAL</var></a></var>
     <span class="initializer"> = 8</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.event.html#event.constants.timeout"><var class="varname">TIMEOUT</var></a></var>
     <span class="initializer"> = 1</span>
    ;</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier">readonly</span>
     <span class="type">bool</span>
      <var class="varname"><a href="class.event.html#event.props.pending">$<var class="varname">pending</var></a></var>
    ;</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="event.add.html" class="methodname">add</a></span>
    ([ <span class="methodparam">
    <span class="type">double</span>
     <code class="parameter">$timeout</code>
   </span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="event.addsignal.html" class="methodname">addSignal</a></span>
    ([ <span class="methodparam">
    <span class="type">double</span>
     <code class="parameter">$timeout</code>
   </span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="event.addtimer.html" class="methodname">addTimer</a></span>
    ([ <span class="methodparam">
    <span class="type">double</span>
     <code class="parameter">$timeout</code>
   </span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><a href="event.construct.html" class="methodname">__construct</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="class.eventbase.html" class="type EventBase">EventBase</a></span>
     <code class="parameter">$base</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$fd</code>
   </span>
   , <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$what</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>
     <code class="parameter">$cb</code>
   </span>
   [, <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$arg</code>
    <span class="initializer"> = NULL</span>
   </span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="event.del.html" class="methodname">del</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="event.delsignal.html" class="methodname">delSignal</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="event.deltimer.html" class="methodname">delTimer</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="event.free.html" class="methodname">free</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="modifier">static</span>
   <span class="type">void</span>
   <span class="methodname"><a href="event.getsupportedmethods.html" class="methodname">getSupportedMethods</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="event.pending.html" class="methodname">pending</a></span>
    ( <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$flags</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="event.set.html" class="methodname">set</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="class.eventbase.html" class="type EventBase">EventBase</a></span>
     <code class="parameter">$base</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$fd</code>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$what</code>
   </span>
   [, <span class="methodparam">
    <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>
     <code class="parameter">$cb</code>
   </span>
   [, <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$arg</code>
   </span>
  ]]] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="event.setpriority.html" class="methodname">setPriority</a></span>
    ( <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$priority</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="event.settimer.html" class="methodname">setTimer</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="class.eventbase.html" class="type EventBase">EventBase</a></span>
     <code class="parameter">$base</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>
     <code class="parameter">$cb</code>
   </span>
   [, <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$arg</code>
   </span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="modifier">static</span>
   <span class="type">Event</span>
   <span class="methodname"><a href="event.signal.html" class="methodname">signal</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="class.eventbase.html" class="type EventBase">EventBase</a></span>
     <code class="parameter">$base</code>
   </span>
   , <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$signum</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>
     <code class="parameter">$cb</code>
   </span>
   [, <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$arg</code>
   </span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="modifier">static</span>
   <span class="type">Event</span>
   <span class="methodname"><a href="event.timer.html" class="methodname">timer</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="class.eventbase.html" class="type EventBase">EventBase</a></span>
     <code class="parameter">$base</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>
     <code class="parameter">$cb</code>
   </span>
   [, <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$arg</code>
   </span>
  ] )</div>

   }</div>

  </div>

  <div class="section" id="event.props">
   <h2 class="title">属性</h2>
   <dl>

    
     <dt id="event.props.pending">
      <var class="varname"><var class="varname">pending</var></var>
     </dt>

     <dd>

      <p class="para">
       Whether event is pending. See
       <a href="event.persistence.html" class="link">About event persistence</a>
       .
      </p>
     </dd>

    
   </dl>

  </div>


  <div class="section" id="event.constants">
   <h2 class="title">预定义常量</h2>
   <dl>

    
     <dt id="event.constants.et">
      <strong><code>Event::ET</code></strong>
     </dt>

     <dd>

      <p class="para">
       Indicates that the event should be edge-triggered, if the underlying
       event base backend supports edge-triggered events. This affects the
       semantics of
       <strong><code>Event::READ</code></strong>
       and
       <strong><code>Event::WRITE</code></strong>
       .
      </p>
     </dd>

    
    
     <dt id="event.constants.persist">
      <strong><code>Event::PERSIST</code></strong>
     </dt>

     <dd>

      <p class="para">
       Indicates that the event is persistent. See
       <a href="event.persistence.html" class="link">About event persistence</a>
       .
      </p>
     </dd>

    
    
     <dt id="event.constants.read">
      <strong><code>Event::READ</code></strong>
     </dt>

     <dd>

      <p class="para">
       This flag indicates an event that becomes active when the provided file
       descriptor(usually a stream resource, or socket) is ready for reading.
      </p>
     </dd>

    
    
     <dt id="event.constants.write">
      <strong><code>Event::WRITE</code></strong>
     </dt>

     <dd>

      <p class="para">
       This flag indicates an event that becomes active when the provided file
       descriptor(usually a stream resource, or socket) is ready for reading.
      </p>
     </dd>

    
    
     <dt id="event.constants.signal">
      <strong><code>Event::SIGNAL</code></strong>
     </dt>

     <dd>

      <p class="para">
       Used to implement signal detection. See &quot;Constructing signal events&quot;
       below.
      </p>
     </dd>

    
    
     <dt id="event.constants.timeout">
      <strong><code>Event::TIMEOUT</code></strong>
     </dt>

     <dd>

      <p class="para">
       This flag indicates an event that becomes active after a timeout
       elapses.
      </p>
      <p class="para">
       The
       <strong><code>Event::TIMEOUT</code></strong>
       flag is ignored when constructing an event: one can either set a
       timeout when event is
       <em class="emphasis">added</em>
       , or not. It is set in the
       <em>$what</em>
       argument to the callback function when a timeout has occurred.
      </p>
     </dd>

    
   </dl>

  </div>

 </div>

 












































































<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="event.add.html">Event::add</a> — Makes event pending</li><li><a href="event.addsignal.html">Event::addSignal</a> — Makes signal event pending</li><li><a href="event.addtimer.html">Event::addTimer</a> — Makes timer event pending</li><li><a href="event.construct.html">Event::__construct</a> — Constructs Event object</li><li><a href="event.del.html">Event::del</a> — Makes event non-pending</li><li><a href="event.delsignal.html">Event::delSignal</a> — Makes signal event non-pending</li><li><a href="event.deltimer.html">Event::delTimer</a> — Makes timer event non-pending</li><li><a href="event.free.html">Event::free</a> — Make event non-pending and free resources allocated for this
  event.</li><li><a href="event.getsupportedmethods.html">Event::getSupportedMethods</a> — Returns array with of the names of the methods supported in this version of Libevent</li><li><a href="event.pending.html">Event::pending</a> — Detects whether event is pending or scheduled</li><li><a href="event.set.html">Event::set</a> — Re-configures event</li><li><a href="event.setpriority.html">Event::setPriority</a> — Set event priority</li><li><a href="event.settimer.html">Event::setTimer</a> — Re-configures timer event</li><li><a href="event.signal.html">Event::signal</a> — Constructs signal event object</li><li><a href="event.timer.html">Event::timer</a> — Constructs timer event object</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="event.constructing.signal.events.html">Constructing signal events</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="event.add.html">Event::add</a></div>
 <div class="up"><a href="book.event.html">Event</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
